<template>
  <div class="divBox relative">
    <el-card class="box-card" style="min-height: 80vh">
      <div slot="header" class="clearfix" style="margin-bottom: -20px ;">
        <div class="container">
          <el-form :inline="true" :model="queryForm" @submit.native.prevent>
            <el-form-item>
              <el-input v-model="queryForm.userid" placeholder="请输入id"  clearable @keyup.enter.native="search()"></el-input>
            </el-form-item>
            <el-form-item>
              <el-input v-model="queryForm.userniname" placeholder="请输入用户名" clearable @keyup.enter.native="search()"></el-input>
            </el-form-item>
            <el-form-item>
              <el-input v-model="queryForm.userphone" placeholder="请输入用户手机号" clearable @keyup.enter.native="search()"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button @click="search()">查询</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <el-table :data="dataList" v-loading="dataListLoading" @selection-change="selectionChangeHandle" style="width: 100%;" size="mini"
                :highlight-current-row="true" :header-cell-style=" {fontWeight:'bold'}"
                :default-sort = "{prop: 'createtime', order: 'descending'}"
                @sort-change="sortChange"
      >
        <el-table-column type="selection" header-align="center" align="center" width="50"/>
        <el-table-column prop="userid" label="用户ID" :show-overflow-tooltip="true" width="160px"></el-table-column>
        <!--           <el-table-column prop="userwxloginkey" label="第三方微信唯一标识符" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="userqqkey" label="第三方qq唯一标识符" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="phonedeviceid" label="手机设备Id" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="userpwd" label="用户密码" :show-overflow-tooltip="true"></el-table-column>-->
        <el-table-column prop="userniname" label="用户名" :show-overflow-tooltip="true" width="100px"></el-table-column>
        <el-table-column prop="userphone" label="手机号"  width="120px"></el-table-column>
        <!--           <el-table-column prop="openid" label="用户唯一标识符" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="accesstoken" label="调用接口需要用到的token" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="expiredtime" label="授权过期时间" :show-overflow-tooltip="true"></el-table-column>-->
        <el-table-column prop="userimg" label="用户头像" :show-overflow-tooltip="true">
          <template slot-scope="scope"  >
            <el-image  fit="scaleDown"
                       :src="scope.row.userimg" :preview-src-list="[scope.row.userimg]">
            </el-image>
          </template>
        </el-table-column>
        <el-table-column prop="bgimg" label="背景图片" :show-overflow-tooltip="true">
          <template slot-scope="scope"  >
            <el-image  fit="scaleDown"
                       :src="scope.row.bgimg" :preview-src-list="[scope.row.bgimg]">
            </el-image>
          </template>
        </el-table-column>
        <!--           <el-table-column prop="userwxlogin" label="用户微信" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="userqqlogin" label="用户QQ号" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="usernum" label="用户账号" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="propelling" label="是否推送(1不推送,2推送)" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="candynum" label="糖果数量" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="versioninfoid" label="版本更新主键" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="identityid" label="身份证表主键" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="invitationcode" label="邀请码" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="firstlogin" label="是否初次登录(1初次登录,2非初次登录)" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="firstupdatename" label="是否修改过用户名(1否,2是)" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="daycandynum" label="每天的分享糖果数量" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="downloadnumy" label="每日下载APP糖果数量" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="registersource" label="注册来源：1Bt商店、2Bt头条" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="updateversion" label="账户更新版本号，更新即自增1" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="candyfreeze" label="金币冻结账户" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="toutiaocandyday" label="头条每日得金币累计数量" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="usertype" label="身份类型：1普通用户、2企业开发者、3个人开发者" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="developerstatus" label="开发者认证状态：1未认证、已认证" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="userip" label="用户手机IP地址" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="phonemac" label="手机mac地址" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="phonebrand" label="手机品牌" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="phonemodel" label="手机型号" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="phonelevel" label="手机系统版本代号(如20)" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="registerchannel" label="注册渠道来源" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="btchatstatus" label="1chat用户" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="loginaddress" label="登录位置" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="longitude" label="登录经度" :show-overflow-tooltip="true"></el-table-column>-->
        <el-table-column prop="gender" label="性别" :show-overflow-tooltip="true">
          <template slot-scope="scope"  >
            <el-tag type="warning" v-if="scope.row.gender==1" >男</el-tag>
            <el-tag type="warning" v-else-if="scope.row.gender==2" >女</el-tag>
            <el-tag type="warning" v-else="scope.row.gender==0" >-</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="city" label="城市" :show-overflow-tooltip="true"></el-table-column>

        <!--           <el-table-column prop="birthday" label="生日" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="age" label="年龄" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="occupation" label="职业" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="signature" label="个性签名" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="chatno" label="大学生号(对应IM服务t_user表_name)" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="xingzuo" label="星座" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="detailsaddr" label="" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="ifvip" label="800:不是vip，866:月vip，886:季vip，888:年vip，666内部使用" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="startvip" label="会员开始时间" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="endvip" label="vip到期时间" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="nearbycount" label="附近的人查看次数限制" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="greetuser" label="打招呼次数限制" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="secret" label="私聊次数统计" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="mark" label="注册渠道" :show-overflow-tooltip="true"></el-table-column>-->
        <!--           <el-table-column prop="userexist" label="是否是真实用户0：真实用户，1：虚拟用户" :show-overflow-tooltip="true"></el-table-column>-->
<!--        <el-table-column prop="deleteuser" label="状态" >-->
<!--          <template slot-scope="scope" >-->
<!--            <el-switch-->
<!--              v-model="scope.row.deleteuser==1"-->
<!--              :active-value="true"-->
<!--              :inactive-value="false"-->
<!--              active-text="启用"-->
<!--              inactive-text="封禁"-->
<!--              @change="change(scope.row)"-->
<!--            />-->
<!--          </template>-->
<!--        </el-table-column>-->

        <el-table-column prop="logintime" label="登录时间" :show-overflow-tooltip="true" width="150" sortable ></el-table-column>
        <el-table-column prop="createtime" label="创建时间" :show-overflow-tooltip="true" width="150" sortable ></el-table-column>
        <!--        <el-table-column prop="modifytime" label="修改时间" :show-overflow-tooltip="true"></el-table-column>-->

        <el-table-column fixed="right" header-align="center" align="center" width="150" label="操作">
          <template slot-scope="scope">
            <el-button type="text"  v-if="checkPermi(['userentity:index:update'])" size="small" @click="addOrUpdateHandle(scope.row.userid)">修改</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="tableForm.pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="tableForm.pageSize"
        :total="tableForm.total"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
    </el-card>
    <!-- 表单弹窗, 新增数据和修改数据 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    <update  v-if="addOrUpdateVisible" ref="update" @refreshDataList="getDataList"></update>
  </div>
</template>

<script>
  import AddOrUpdate from './userentity-add-and-update.vue'
  import update from './update.vue'
  import api from '@/api/api'
  import {checkPermi} from "@/utils/permission";
  import Cookies from 'js-cookie'

  export default {
    components: {
      AddOrUpdate,update
    },
    data () {
      return {
        dataList: [],
        queryForm: {
          userid: '',
          userniname:'',
          userphone:'',
          userexist:1
        },
        tableForm:{
          pageIndex: 1,
          pageSize: 10,
          total: 0,
        },
        sort:{
          order:'desc',
          column:'createtime'
        },
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    mounted () {
      this.getDataList()
    },
    methods: {
      checkPermi,
      // 每页数
      sizeChangeHandle (val) {
        this.tableForm.pageSize = val
        this.tableForm.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.tableForm.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      sortChange(a){
        this.sort.order=a.order.replace('ending','')
        this.sort.column=a.prop
        this.search();
      },
      search(){
        this.tableForm.pageIndex = 1
        this.getDataList()
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.dataListLoading = true
        let postData={
          'order':'desc',
          'column':'createtime'
        }
        Object.assign(postData,this.queryForm, this.tableForm,this.sort)

        let JavaInfo = JSON.parse(Cookies.get('JavaInfo'))
        postData.adminid=JavaInfo.id;
        postData.userniname=api.getLikeValue( postData.userniname);
        api.post('rest/vabc/userEntity/list',postData).then(res => {
          this.dataList=res.datalist
          this.tableForm.total=res.total
        }).finally(() => {
          this.dataListLoading = false
        });
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        if (id){
          this.$refs.update.init(id)
        }else {
          this.$nextTick(() => {
            this.$refs.addOrUpdate.init(id)
          })
        }

      },
      change(row){
        let postData={userid:row.userid}
        postData.deleteuser=row.deleteuser==1?2:1;
        let msg=postData.deleteuser==2?'您确定封禁当前用户吗？':'您确定解封当前用户吗？';
        this.$confirm(msg, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          api.post('rest/vabc/userEntity/change',postData).then(res => {
            this.$message.success("操作成功")
            row.deleteuser=postData.deleteuser
          })
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.userid
        })
        this.$confirm(`您确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let postData={ids:ids.join(',')};
          api.post('rest/vabc/userEntity/delete',postData).then(res => {
            this.$message.success("删除成功")
            this.getDataList()
          })
        })
      }
    }
  }
</script>
